<template>
    <div class="centerBox">
        <ul class="centerTop">
            <li class="liB">
                <p class="biaoNum t1">
                    {{ numberFormat(indexData.index1).value }}
                    <span class="unit">
                        {{ numberFormat(indexData.index1).unit }}</span
                    >
                </p>
                <p class="biao">本年出口额($)</p>
            </li>
            <li class="liB">
                <p class="biaoNum t2">
                    {{ numberFormat(indexData.index2).value }}
                    <span class="unit">
                        {{ numberFormat(indexData.index2).unit }}</span
                    >
                </p>
                <p class="biao">本年进口额($)</p>
            </li>
            <li class="liB">
                <p class="biaoNum t3">
                    {{ numberFormat(indexData.index3).value }}
                    <span class="unit">
                        {{ numberFormat(indexData.index3).unit }}</span
                    >
                </p>
                <p class="biao">累计出口额($)</p>
            </li>
            <li class="liB">
                <p class="biaoNum t4">
                    {{ numberFormat(indexData.index4).value }}
                    <span class="unit">
                        {{ numberFormat(indexData.index4).unit }}</span
                    >
                </p>
                <p class="biao">累计进口额($)</p>
            </li>
            <li class="liB">
                <p class="biaoNum t5">
                    {{ indexData.index5 }} <span class="unit">个</span>
                </p>
                <p class="biao">国家和地区</p>
            </li>
            <li class="liB">
                <p class="biaoNum t6">
                    {{ indexData.index6 }} <span class="unit">个</span>
                </p>
                <p class="biao">境外客户数</p>
            </li>
        </ul>
        <div class="map-container">
            <div class="mapsbBox">
                <div class="mapsbBoxT">
                    <div :id="id" ref="myEchart" class="map-chart"></div>
                </div>
                <div class="mapsbBoxB">
                    <div
                        id="centerChart1"
                        style="width: 100%; height: 100%"
                    ></div>
                </div>
            </div>
            <!-- <div class="mapRoll">
                <div class="rolltext">
                    <span class="water_text"
                        >外贸综合服务为核心的产业供应链集成服务，以数字生活服务为核心的消费品供应链集成服务</span
                    >
                </div>
            </div> -->
            <div class="recheck" @click="gopath"></div>
        </div>
    </div>
</template>
  
  <script>
import * as echarts from 'echarts/lib/echarts'
import 'echarts-gl'
import WorldJson from '@/assets/json/worlds.json'
import zhejiang from '@/assets/map/zhejiang.json'
import { mapZHName } from '@/utils/mapZHName.js'
import { screenMidData, screenLeftData } from '@/api/export.js'

export default {
    data() {
        return {
            // 指标
            indexData: {
                index1: 0,
                index2: 0,
                index3: 0,
                index4: 0,
                index5: 0,
                index6: 0
            },
            id: 'echarts_',
            option: {
                tooltip: {
                    show: true,
                    borderColor: 'rgba(17,55,118,0.7)',
                    borderWidth: 1,
                    padding: [5, 5],
                    backgroundColor: 'rgba(17,55,118,0.7)',
                    borderRadius: 10,
                    textStyle: {
                        color: '#e4e5ea'
                    }
                },
                visualMap: {
                    show: false,
                    left: 'right',
                    min: 0, //指定 visualMapContinuous 组件的允许的最小值。
                    max: 74545459, //指定 visualMapContinuous 组件的允许的最大值
                    inRange: {
                        color: [
                            // '#87CEFA',
                            // '#87CEEB',
                            '#00BFFF',
                            '#1E90FF',
                            '#0000FF'
                        ]
                    },
                    calculable: true //是否显示拖拽用的手柄（手柄能拖拽调整选中范围）。
                },

                series: [
                    {
                        name: '世界',
                        type: 'map3D',
                        map: '世界', //地图类型。echarts-gl 中使用的地图类型同 geo 组件相同
                        regionHeight: 2, //模型的高度
                        boxWidth: 100, //三维地图在三维场景中的宽度
                        // boxHeight: 100,
                        boxDepth: 53, //三维地图在三维场景中的深度
                        top: '0%',
                        bottom: '-22%',
                        left: '-4%',
                        label: {
                            show: false, //是否显示标签。
                            position: ['50%', '50%'],
                            formatter: (params) => {
                                params.name
                            },
                            color: 'rgba(255,255,255,0.65)', //地图初始化区域字体颜色
                            fontSize: 12,
                            opacity: 1,
                            backgroundColor: '#1B212B ',
                            borderColor: '#998484',
                            borderWidth: 1,
                            position: 'insideTop',
                            padding: 4,
                            borderRadius: 2,
                            distance: 0
                        },
                        itemStyle: {
                            //静态模式下显示的默认样式
                            borderWidth: 1,
                            borderColor: '#95FFFF',
                            color: '#87CEFA' //阴影效果
                        },
                        emphasis: {
                            label: {
                                show: false
                            },
                            // 鼠标移上去的样式
                            borderWidth: 1.6,
                            borderColor: '#95FFFF',
                            color: '#8697ba',
                            textStyle: {
                                color: '#8697ba'
                            }
                        },
                        legend: {
                            show: false,
                            textStyle: {
                                color: '#8697ba'
                            }
                        },
                        viewControl: {
                            //用于鼠标的旋转，缩放等视角控制。
                            autoRotate: false, //是否开启视角绕物体的自动旋转查看
                            autoRotateAfterStill: 1,
                            distance: 56, //默认视角距离主体的距离，对于 globe 来说是距离地球表面的距离，对于 grid3D 和 geo3D 等其它组件来说是距离中心原点的距离。在 projection 为'perspective'的时候有效。
                            minAlpha: 80, // 上下旋转的最小 alpha 值。即视角能旋转到达最上面的角度。[ default: 5 ]
                            maxAlpha: 90, // 上下旋转的最大 alpha 值。即视角能旋转到达最下面的角度。[ default: 90 ]
                            minBeta: -360, // 左右旋转的最小 beta 值。即视角能旋转到达最左的角度。[ default: -80 ]
                            maxBeta: 360, // 左右旋转的最大 beta 值。即视角能旋转到达最右的角度。[ default: 80 ]
                            animation: true, // 是否开启动画。[ default: true ]
                            animationDurationUpdate: 1000, // 过渡动画的时长。[ default: 1000 ]
                            animationEasingUpdate: 'cubicInOut' // 过渡动画的缓动效果。[ default: cubicInOut ]
                        },
                        data: [{ name: '中国', value: 300 }]
                    }
                ]
            },

            centerChart1: null
        }
    },
    mounted() {
        // 世界地图
        //     this.echartObj = echarts.init(document.getElementById(this.id))
        // echarts.registerMap('世界', WorldJson)
        // this.echartObj.setOption(this.option, true)
        this.CenterChartgetall()
    },
    computed: {},
    methods: {
        CenterChartgetall(data) {
            let istype = ''
            if (!data || data == '全部') {
                istype = ''
            } else {
                istype = data
            }
            screenMidData({ type: istype }).then((res) => {
                // 指标
                this.indexData = { ...res.data.Index }
                // 地图映射
                this.echartObj = echarts.init(document.getElementById(this.id))
                let isZhWorldJson = this.formatWorldMapToZH(WorldJson)
                echarts.registerMap('世界', isZhWorldJson)
                this.option.series[0].data = res.data.CountryData
                this.echartObj.setOption(this.option, true)
                // 柱形图
                let xAxisdata1 = res.data.CountryDataChart.line.xAxis.map(
                    (item) => {
                        return item
                    }
                )
                let seriesdata1 = res.data.CountryDataChart.line.series.map(
                    (item) => {
                        let obj = {
                            name: item.name,
                            type: 'bar',
                            barWidth: 11,
                            barGap: '0%',
                            emphasis: {
                                focus: 'series'
                            },
                            data: item.data
                        }
                        return obj
                    }
                )
                this.drawcenterChart1(xAxisdata1, seriesdata1)
            })
        },

        // 转换单位
        numberFormat(val) {
            let value = val - 0
            let param = {}
            let k = 10000
            let sizes = ['', '万', '亿', '万亿']
            let i = 0
            if (value < k) {
                param.value = value
                param.unit = ''
            } else {
                i = Math.floor(Math.log(value) / Math.log(k))
                param.value = (value / Math.pow(k, i)).toFixed(2)
                param.unit = sizes[i]
            }
            return param
        },
        // 转换单位
        keepTwoDecimalFull(num) {
            if (num > 10000) {
                let result = num / 10000
                result = Math.floor(result * 100) / 100
                var s_x = result.toString() //将数字转换为字符串
                var pos_decimal = s_x.indexOf('.') //小数点的索引值// 当整数时，pos_decimal=-1 自动补0
                if (pos_decimal < 0) {
                    pos_decimal = s_x.length
                    s_x += '.'
                } // 当数字的长度< 小数点索引+2时，补0
                while (s_x.length <= pos_decimal + 2) {
                    s_x += '0'
                }
                s_x += '万'
            } else {
                s_x = num
            }
            return s_x
        },
        drawcenterChart1(xAxisdata, seriesdata) {
            this.centerChart1 = this.$echarts.init(
                document.getElementById('centerChart1')
            )
            let option = {
                color: ['#E9CF65', '#037BD8'],

                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                legend: {
                    top: '10',
                    right: '2%',
                    // x: '50%',
                    textStyle: {
                        fontSize: 14,
                        color: '#B4B4B4'
                    },
                    show: true
                },
                grid: {
                    left: '0%',
                    right: '0%',
                    bottom: '0%',
                    top: '5%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        // boundaryGap: false,
                        axisLine: {
                            show: true,
                            lineStyle: {
                                color: '#35527C'
                            }
                        },
                        axisLabel: {
                            interval: 0, //横轴信息全部显示
                            rotate: 20, //-30度角倾斜显示
                            color: '#8697BA', //坐标的字体颜色
                            fontSize: 12
                        },
                        axisTick: {
                            show: false
                        },
                        // splitLine: {
                        //     show: true,
                        //     //  改变轴线颜色
                        //     lineStyle: {
                        //         // 使用深浅的间隔色
                        //         color: ['#35527C']
                        //     }
                        // },
                        data: xAxisdata
                    }
                ],
                yAxis: [
                    {
                        axisLine: {
                            show: true,
                            lineStyle: {
                                color: '#35527C'
                            }
                        },
                        type: 'value',

                        axisLabel: {
                            color: '#8697BA', //坐标的字体颜色
                            fontSize: 12
                        },
                        splitLine: {
                            show: false,
                            //  改变轴线颜色
                            lineStyle: {
                                // 使用深浅的间隔色
                                color: ['#35527C']
                            }
                        }
                    }
                ],
                series: seriesdata
            }
            this.centerChart1.setOption(option)
        },
        // 主屏
        gopath() {
            this.$router.push({
                path: '/'
            })
        },
        formatWorldMapToZH(data) {
            let zhFeatures = []
            if (data.features) {
                zhFeatures = data.features.map((item) => {
                    if (mapZHName[item.properties.name]) {
                        item.properties.name = mapZHName[item.properties.name]
                    }
                    return item
                })
            }
            data.features = zhFeatures
            return data
        }
    },
    beforeDestroy() {
        //清除定时器
    }
}
</script>
  
  <style scoped lang='scss'>
.centerBox {
    width: 100%;
    vertical-align: top;
    position: relative;
    p {
        padding: 0;
        margin: 0;
    }
    .centerTop {
        width: 100%;
        display: flex;
        justify-content: space-between;
        margin-top: 51px;
        .liB {
            width: 124px;
            height: 83px;
            text-align: center;
            background-image: url('../../../assets/cockpit/boxi.png');
            background-size: 100% 100%;
            // background-position: center center;
            .biao {
                font-size: 16px;
                font-weight: 400;
                color: #ffffff;
                margin-top: 8px;
            }
            .biaoNum {
                font-size: 32px;
                font-family: 'Yourname';
                font-weight: 500;
                color: #23acf3;
                margin-top: 13px;
                .unit {
                    font-size: 15px;
                    color: #ffffff;
                    font-weight: 400;
                    font-family: 'fangzheng';
                    margin-left: -4px;
                }
            }
            .t1 {
                color: #ffb33a;
            }
            .t2 {
                color: #23acf3;
            }
            .t3 {
                color: #f60783;
            }
            .t4 {
                color: #3ffdb4;
            }
            .t5 {
                color: #00f9ff;
            }
            .t6 {
                color: #ffb33a;
            }
        }
    }
    .map-container {
        width: 100%;
        height: 480px;
        margin-top: 10px;
        position: relative;
        .mapsbBox {
            width: 100%;
            height: 480px;
            background-image: url('../../../assets/exportScreen/bbsMox.png');
            background-size: 100% 100%;

            // background-size: cover;
            // background-position: center center;
            box-sizing: border-box;
            padding: 20px 20px 20px 30px;
            .mapsbBoxT {
                width: 100%;
                height: 310px;
            }
            .mapsbBoxB {
                width: 95%;
                height: 130px;
                margin: 10px auto 0;
            }
            .map-chart {
                z-index: 5;
                height: 100%;
                width: 100%;
                // animation: shake; /*动画名称*/
                // animation-timing-function: linear;
                // animation-duration: 2; /*动画持续时间*/
                // -webkit-animation: shake 3s; /*针对webkit内核*/
            }
        }
        .mapRoll {
            width: 100%;
            height: 103px;
            background-image: url('../../../assets/cockpit/centBot.png');
            background-size: cover;
            background-position: center center;
            position: absolute;
            left: 0;
            bottom: 3px;
            z-index: 2;
            .rolltext {
                width: 630px;
                overflow: hidden;
                height: 37px;
                line-height: 37px;
                position: absolute;
                top: 15px;
                left: 56px;
            }
            .water_text {
                white-space: nowrap;
                position: absolute;
                display: inline-block;
                top: 0px;
                animation: 16s scroll linear infinite normal;
                font-size: 18px;
                color: #ffffff;
                font-family: 'pingfang';
                letter-spacing: 1px;
            }

            @keyframes scroll {
                0% {
                    right: 0%;
                }
                100% {
                    right: 100%;
                }
            }
        }
        .recheck {
            width: 70px;
            height: 70px;
            background-image: url('../../../assets/cockpit/close.png');
            background-size: cover;
            background-position: center center;
            position: absolute;
            right: -17px;
            bottom: -22px;
            z-index: 3;
            cursor: pointer;
        }
    }
}
@keyframes shake {
    0% {
        transform: scale(0);
        transform: rotate3d(1, 1, 1, 360deg);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        transform: rotate3d(1, 1, 1, 0deg);
        opacity: 1;
    }
}
@-webkit-keyframes shake {
    0% {
        transform: scale(0);
        transform: rotate3d(1, 1, 1, 360deg);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        transform: rotate3d(1, 1, 1, 0deg);
        opacity: 1;
    }
}
@keyframes scaleDraw {
    /*定义关键帧、scaleDrew是需要绑定到选择器的关键帧名称*/
    0% {
        transform: scale(1); /*开始为原始大小*/
    }
    50% {
        transform: scale(1.2); /*放大1.1倍*/
    }
}
</style>
  